import store from '@/store'
import axios from 'axios'

const request = axios.create({
  baseURL: 'https://lianghj.top:8888/api',
  // baseURL: 'http://weldon.net.cn:8889/api',
  timeout: 5000,
})

// 请求拦截器
request.interceptors.request.use(
  (config) => {
    const token = store.state.user.token
    if (token) {
      config.headers.Authorization = token
    }
    return config
  },
  (err) => {
    return Promise.reject(err)
  }
)
// 响应拦截器
request.interceptors.response.use(
  // 成功
  (response) => {
    return response.data
  },
  (err) => {
    return Promise.reject(err)
  }
)
export default request
